Skip to content

Fix canvas not resizing with window resize#1

Merged
Tomywang999 merged 5 commits intomainfrom
copilot/fix-field-area-canvas-resize
Nov 7, 2025
Merged

Fix canvas not resizing with window resize#1
Tomywang999 merged 5 commits intomainfrom
copilot/fix-field-area-canvas-resize

Conversation

Copy link

Copilot AI commented Nov 7, 2025

The Two.js canvas and D3 scales don't automatically update when the window is resized, causing visual elements to remain at incorrect positions.

Changes

  • Added resize handler: Calls two.fit() on window resize to update canvas dimensions
  • Added resize trigger: Introduced resizeTrigger variable to force reactive recalculation of D3 scales
  • Updated reactive scales: Modified x and y scale declarations to depend on resizeTrigger
// Reactive scales now update on window resize
$: {
  void resizeTrigger; // Force reactive update when resizeTrigger changes
  x = d3
    .scaleLinear()
    .domain([0, 144])
    .range([0, twoElement?.clientWidth ?? 144]);
}

// Resize handler updates both canvas and triggers scale recalculation
const handleResize = () => {
  if (two) {
    two.fit();
    resizeTrigger++;
  }
};

The window resize event listener is added in onMount and cleaned up in onDestroy.

Original prompt

Fix window resize leading to the main canva of the field area display incorrectly that does not resize with the window changes.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits November 7, 2025 07:33
Co-authored-by: Tomywang999 <103342866+Tomywang999@users.noreply.github.com>
Co-authored-by: Tomywang999 <103342866+Tomywang999@users.noreply.github.com>
Co-authored-by: Tomywang999 <103342866+Tomywang999@users.noreply.github.com>
Co-authored-by: Tomywang999 <103342866+Tomywang999@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix window resize issue with field area canvas Fix canvas not resizing with window resize Nov 7, 2025
Copilot AI requested a review from Tomywang999 November 7, 2025 07:42
@Tomywang999 Tomywang999 marked this pull request as ready for review November 7, 2025 08:43
@Tomywang999 Tomywang999 merged commit 0a4cddd into main Nov 7, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants